<template>
	<scroll-view scroll-y="true" class="container_scrollview" :show-scrollbar="false">
		<view class="container">
			<!-- 菜单 -->
			<view class="" v-for="item in yhqlist">
				<view class="kuang">
					<view class="quan">
						<view class="fl_ju">
							<view class="title">
								{{item.name}}元券
							</view>
							<view class="qian">
								¥{{item.amount/100}}
							</view>
						</view>
						<view class="fl_ju" style="margin: 30rpx 0;">
							<view class="time">
								有效期：{{item.startTime}}至{{item.endTime}}
							</view>
							<view class="man">
								{{item.useConditionContent}}
							</view>
						</view>
						<view class="" style="display: flex;justify-content: flex-end;">
							<view class="" style="width: 200rpx;">
								<u-button text="已领取" v-if="item.isClaim==1" :hairline="false"
									color="#cecece"></u-button>
								<u-button text="领取" v-else @click="linqu(item.id)"
									color="linear-gradient(to right,#3AA3FF, #005DFF)"></u-button>

							</view>
						</view>

					</view>
				</view>
			</view>
			<u-empty mode="coupon" textSize="30" iconSize="50" width="300rpx" height="300rpx" v-if="yhqlist.length==0" icon="http://cdn.uviewui.com/uview/empty/car.png">
			</u-empty>
		</view>
	</scroll-view>
</template>

<script>
	import {
		couponTemplateList,
		couponAdd
	} from '@/api/url.js'
	export default {
		data() {
			return {
				list1: [{
					name: '未使用',
				}, {
					name: '已使用',
				}, {
					name: '已过期'
				}],
				columns: [],
				yhqlist: [],
				params: {
					pageNum: 1,
					pageSize: 10,
					canBeClaimed: 0,
					isDisplay: 0
				},
				token: uni.getStorageSync("token")
			};
		},

		computed: {

		},
		onShow() {

		},
		onLoad() {
			this.list()
		},
		methods: {
			click(item) {
				console.log('item', item);
			},
			list() {
				couponTemplateList(this.params, this.token).then(res => {
					console.log(res)
					this.yhqlist = res.data.rows
				})
			},
			linqu(e) {
				console.log(e)
				couponAdd({
					templateId: e
				}, this.token).then(res => {
					console.log(res.data.code)
					if (res.data.code == 200) {
						uni.showToast({
							title: '领取成功~',
							icon: 'none',
							duration: 1000
						})
						this.list()
					}
				})
			}
		},
	};
</script>

<style lang="scss" scoped>
	@import "./index.scss";

	.quan {
		.title {
			font-weight: 600;
		}

		.qian {
			color: red;
			font-weight: 600;
		}

		.time {
			color: #AAAAAA;
			font-size: 24rpx;
		}

		.man {
			color: #2C2C2C;
			font-size: 30rpx;
		}
	}
</style>